<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>找回密码-{eyou:global name='web_name' /}</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<link href="{eyou:global name='web_cmspath' /}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    {eyou:static file="users/skin/css/basic.css" /}
    {eyou:static file="users/skin/css/eyoucms.css" /}
    {eyou:include file="users/skin/css/diy_css.htm" /}
    
    {eyou:static file="/public/static/common/js/jquery.min.js"/}
    {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
    {eyou:static file="users/skin/js/global.js" /}
</head>

<body class="reg retrieve">


<div class="register_index ey-member">
    <div class="container">
    <form name='theForm' id="theForm" class="form-register panel-body fv-form">
        <div class="mip-reg-logo"><a href="{eyou:global name='web_cmsurl' /}" class="ey-logo"><img src="{eyou:global name='web_logo'/}" /></a></div>
        <div class="mip-reg-heading">找回密码</div>
        <div class="form-group group_z">
            <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-envelope-o"></i></span>
                <input type="text" name="email" id="email" class="form-control" placeholder="邮箱地址"/>
            </div>
        </div>

        <div class="form-group group_z">
            <div class="input-group btn-direction">
                <span class="input-group-addon"><i class="fa fa-shield"></i></span>
                <div class="formText">
                    <input type="text" class="form-control" id="email_code" name="email_code" placeholder="邮箱验证码" />
                </div>
                <input type="button" id="email_code_button" onclick="send_email();" class="btn btn-primary sento" value="点击发送" />
            </div>
        </div>

        {eyou:eq name="$is_vertify" value="1"}
        <div class="form-group group_z">
            <div class="input-group input-group-icon">
                <span class="input-group-addon"><i class="fa fa-shield"></i></span>
                <div class="formText">
                    <input type="text" name="vertify" id="vertify" autocomplete="off" class="form-control" placeholder="图片验证码" />
                    <img src="{eyou:url link='api/Ajax/vertify' vars='type=users_retrieve_password' /}" class="chicuele" id="imgVerifys" onClick="fleshVerify();">
                </div>
            </div>
        </div>
        {/eyou:eq}

        <button class="btn btn-lg btn-primary btn-block group_z" style="width: 100%;" onclick="check_submit();" type="button">下一步</button>
        <div class="login_link"><a class="login_link_register" href="{eyou:url link='user/Users/login' /}">返回登录</a></div>
    </form>
    </div>
</div>

<script type="text/javascript">
    $(document).keydown(function(event){
        if(event.keyCode ==13){
            check_submit();
        }
    });
    
    function fleshVerify(){
        var src = "{eyou:url link='api/Ajax/vertify' vars='type=users_retrieve_password' /}";
        if (src.indexOf('?') > -1) {
            src += '&';
        } else {
            src += '?';
        }
        src += 'r='+ Math.floor(Math.random()*100);
        $('#imgVerifys').attr('src', src);
    }

    function check_submit()
    {   
        var email = $('#email').val();
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        // 邮箱格式不正确
        if(!reg.test(email)){
            layer.msg('邮箱格式不正确，请正确输入邮箱地址！', {time: 1500});
            return false;
        }

        var email_code = $('#email_code').val();
        if(email_code == ''){
            layer.msg('邮箱验证码不能为空', {time: 1000});
            return false;
        }

        layer_loading('正在处理');
        $.ajax({
            // async:false,
            url: "{eyou:url link='user/Users/retrieve_password' /}",
            data: $('#theForm').serialize(),
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if (res.code == 1) {
                    window.location.href = res.url;
                } else {
                    layer.msg(res.msg, {time: 2000, icon: 5});
                }
            },
            error : function(e) {
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    };

    function send_email(email){
        var email = $('#email').val();
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        // 邮箱格式不正确
        if(!reg.test(email)){
            layer.msg('邮箱格式不正确，请正确输入邮箱地址！', {time: 1500});
            return false;
        }

        $("#email_code_button").val('发送中…');
        $("#email_code_button").attr('disabled', 'disabled');
        layer_loading('正在处理');
        $.ajax({
            url: "{eyou:url link='user/Smtpmail/send_email' /}",
            data: {email:email,title:'找回密码',type:'retrieve_password',scene:4},
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if(res.code == 1){
                    countdown();
                    layer.msg(res.msg, {time: 1000});
                }else{
                    $("#email_code_button").val('点击发送');
                    $("#email_code_button").removeAttr("disabled");
                    showErrorAlert(res.msg);
                }
            },
            error : function(e) {
                layer.closeAll();
                $("#email_code_button").val('点击发送');
                $("#email_code_button").removeAttr("disabled");
                showErrorAlert(e.responseText);
            }
        });
    };

    function countdown(){
        // 倒计时
        var setTime;
        var time = {php}echo config('global.email_send_time');{/php};
        setTime = setInterval(function(){
            if(0 >= time){
                clearInterval(setTime);
                return;
            }
            time--;
            $("#email_code_button").val(time+'秒');
            $("#email_code_button").attr('disabled', 'disabled');

            if(time == 0){
                $("#email_code_button").val('点击发送');
                $("#email_code_button").removeAttr("disabled");
            }
        },1000);
    }
</script>

</body>
</html>